#include<bits/stdc++.h>
using namespace std;
const int N = 10010;
struct carpet{
	int a , b , c , d , g , k;
}c[N];
int n , x , y;
int main(){
	freopen("carpet.in", "r", stdin);
	freopen("carpet.out", "w", stdout);
	cin >> n;
	for(int i = 1 ; i <= n ; i++){
		cin >> c[i].a >> c[i].b >> c[i].g >> c[i].k;
		c[i].c = c[i].a + c[i].g;
		c[i].d = c[i].b + c[i].k;
	}
	cin >> x >> y;
	for(int i = n ; i >= 1 ; i--){
		if(c[i].a <= x && c[i].b <= y && c[i].b <= y && c[i].d >= y){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}